import { Db, MongoClient } from 'mongodb';

const username = 'admin';
const pwd = 'EKFFHSXsps$nMT00';
const dbUrl = `mongodb://${username}:${pwd}@10.230.221.248:27017`;
const dbName = 'dwfe';

let db: Db | null = null;

async function connect() {
  const client = await MongoClient.connect(dbUrl);
  db = client.db(dbName);
  return db;
}

async function mongodbInstance() {
  if (db) {
    return db;
  }
  return connect();
}

export default mongodbInstance;
